package com.boco.transnms.server.dao.workflow;

import com.boco.transnms.server.dao.base.AbstractDAO;
import com.boco.transnms.server.dao.base.DaoName;
import com.boco.transnms.common.dto.base.DboCollection;
import com.boco.transnms.common.dto.base.BoActionContext;
import com.boco.common.util.except.UserException;
import com.boco.transnms.server.dao.base.ObjectGetTypeEnum;
import com.boco.transnms.common.dto.base.DataObjectList;
import com.boco.transnms.common.dto.SystemPara;

/**
 * <p>Title: </p>
 *
 * <p>Description: WebMaster4.x</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: BOCO</p>
 *
 * @author not attributable
 * @version 4.2.x
 */
public class AttempSystemParaDAO   extends AbstractDAO  {
    public AttempSystemParaDAO() {
          super(DaoName.AttempSystemParaDAO);
    }

    public DboCollection getAttempSystemPara(BoActionContext actionContext) throws Exception{
        String sql = "select * from " + SystemPara.CLASS_NAME;
        sql += " where " + SystemPara.AttrName.productSpName + "='chinamobile'";
        sql += " and (" + SystemPara.AttrName.paraName + "='autoSMSTime' OR "+SystemPara.AttrName.paraName+"='isSendSMSAlarm' OR ";
        sql += SystemPara.AttrName.paraName + "='appSetTime' OR " + SystemPara.AttrName.paraName+"='dgnSetTime' OR "+SystemPara.AttrName.paraName+"='workflowViewRange' OR ";
        sql += SystemPara.AttrName.paraName + "='isArchive' OR " + SystemPara.AttrName.paraName + "='sendFrequency' OR " + SystemPara.AttrName.paraName + "='maxSendTimes')";
        sql += " and " + SystemPara.AttrName.productTypeName + "='TNMS'";
        sql += " order by " + SystemPara.AttrName.paraAddition;
        return super.selectDBOs(sql, new SystemPara());
    }

    public void modifyAttempSystemParas(BoActionContext actionContext,SystemPara[] dbos) throws Exception {
        for(int i=0;i<dbos.length;i++){
            SystemPara dbo = dbos[i];
            if(dbo!=null){
                String sql = "UPDATE " + SystemPara.CLASS_NAME;
                sql += " SET " + SystemPara.AttrName.paraValue + " = '" + dbo.getParaValue() + "'";
                sql += " WHERE " + SystemPara.AttrName.productSpName + " = '" + dbo.getProductSpName() + "'";
                sql += " AND " + SystemPara.AttrName.paraClassName + " = '" + dbo.getParaClassName() + "'";
                sql += " AND " + SystemPara.AttrName.paraName + " = '" + dbo.getParaName() + "'";
                sql += " AND " + SystemPara.AttrName.productTypeName + " = '" + dbo.getProductTypeName() + "'";
                super.execSql(sql);
            }
        }
    }

    public void modifyAttempSysPara(BoActionContext actionContext,SystemPara[] dbos) throws Exception {
        for(int i=0;i<dbos.length;i++){
            SystemPara sysPara = dbos[i];
            if(sysPara!=null){
                String sql = "update " + SystemPara.CLASS_NAME
                             + " set " + SystemPara.AttrName.paraValue + "='" + sysPara.getParaValue() + "'"
                             + " where " + SystemPara.AttrName.paraName + "='" + sysPara.getParaName() + "'"
                             + " and " + SystemPara.AttrName.productSpName + "='" + sysPara.getProductSpName() + "'"
                             + " and " + SystemPara.AttrName.productTypeName + "='" + sysPara.getProductTypeName() + "'";
                super.execSql(sql);
            }
        }
    }

    public SystemPara getSystemPara(BoActionContext actionContext, String productSp, String paraName) throws Exception {
        String sql = "select * from SYSTEM_PARA where " + SystemPara.AttrName.productSpName + "='" + productSp + "' and " + SystemPara.AttrName.paraName + "='" + paraName + "'";
        DboCollection rtn = super.selectDBOs(sql,new SystemPara());
        if(rtn!=null&& rtn.size()>0){
            return (SystemPara) rtn.getAttrField(SystemPara.CLASS_NAME,0);
        }else{
            return null;
        }
    }
}
